package com.javielinux.pruebaservicio;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class PruebaServicio extends Activity implements ServiceUpdateUIListener {
	
	TextView text;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        text = (TextView) findViewById(R.id.count);
                
        Button startButton = (Button) findViewById(R.id.start);
        
        startButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
            	startService();
            }
          
        });
        
        Button stopButton = (Button) findViewById(R.id.stop);
        
        stopButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
            	stopService();
            }
          
        });
        
        MyService.setUpdateListener(this);
        
        
    }
    
    private void startService() {
    	Intent svc = new Intent(this, MyService.class);
        startService(svc);
    }
    
    private void stopService() {
    	Intent svc = new Intent(this, MyService.class);
		stopService(svc);
    }
    

	@Override
	public void update(int count) {
		text.setText("Contador: " + count);
	}

	@Override
	public void update(Estacion estacion) {
		text.setText("Libres: " + estacion.getAvailable());
		
	}
    
}